SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE PROCEDURE dbo.[DnnProduct_UpdatePortalInfo]
	@PortalID				int,
	@PortalGroupID			int,
	@PortalName				nvarchar(128),
	@LogoFile				nvarchar(50),
	@FooterText				nvarchar(100),
	@ExpiryDate				datetime,
	@UserRegistration		int,
	@BannerAdvertising		int,
	@Currency				char(3),
	@AdministratorId		int,
	@HostFee				money,
	@HostSpace				int,
	@PageQuota				int,
	@UserQuota				int,
	@PaymentProcessor		nvarchar(50),
	@ProcessorUserId		nvarchar(50),
	@ProcessorPassword		nvarchar(50),
	@Description			nvarchar(500),
	@KeyWords				nvarchar(500),
	@BackgroundFile			nvarchar(50),
	@SiteLogHistory			int,
	@SplashTabId			int,
	@HomeTabId				int,
	@LoginTabId				int,
	@RegisterTabId			int,
	@UserTabId				int,
	@SearchTabId			int,
	@DefaultLanguage		nvarchar(10),
	@HomeDirectory			varchar(100),
	@LastModifiedByUserID	int,
	@CultureCode			nvarchar(50)

AS

	UPDATE dbo.DnnProduct_Portals
		SET    
		   PortalGroupID		= @PortalGroupID,
		   ExpiryDate			= @ExpiryDate,
		   UserRegistration		= @UserRegistration,
		   BannerAdvertising	= @BannerAdvertising,
		   Currency				= @Currency,
		   AdministratorId		= @AdministratorId,
		   HostFee				= @HostFee,
		   HostSpace			= @HostSpace,
		   PageQuota			= @PageQuota,
		   UserQuota			= @UserQuota,
		   PaymentProcessor		= @PaymentProcessor,
		   ProcessorUserId		= @ProcessorUserId,
		   ProcessorPassword	= @ProcessorPassword,
		   SiteLogHistory		= @SiteLogHistory,
		   DefaultLanguage		= @DefaultLanguage,
		   HomeDirectory		= @HomeDirectory,
		   LastModifiedByUserID = @LastModifiedByUserID,
		   LastModifiedOnDate	= getdate()
	WHERE  PortalId = @PortalID

IF EXISTS (SELECT * FROM dbo.DnnProduct_PortalLocalization WHERE PortalId = @PortalID AND CultureCode = @CultureCode)
	BEGIN 
		UPDATE dbo.DnnProduct_PortalLocalization
			SET
				PortalName				= @PortalName,
				LogoFile				= @LogoFile,
				FooterText				= @FooterText,
				Description				= @Description,
				KeyWords				= @KeyWords,
				BackgroundFile			= @BackgroundFile,
				HomeTabId				= @HomeTabId,
				LoginTabId				= @LoginTabId,
				RegisterTabId			= @RegisterTabId,
				UserTabId				= @UserTabId,
				SplashTabId				= @SplashTabId,
				SearchTabId				= @SearchTabId,
				LastModifiedByUserID	= @LastModifiedByUserID,
				LastModifiedOnDate		= getdate()
		WHERE	PortalId = @PortalID 
			AND CultureCode = @CultureCode
	END 
ELSE
	BEGIN 
		DECLARE @AdminTabId int
		SET @AdminTabId = (SELECT AdminTabId 
								FROM dbo.DnnProduct_PortalLocalization 
								WHERE PortalID = @PortalID AND CultureCode='en-US')

		INSERT INTO dbo.DnnProduct_PortalLocalization (
			[PortalID],
			[CultureCode],
			[PortalName],
			[LogoFile],
			[FooterText],
			[Description],
			[KeyWords],
			[BackgroundFile],
			[HomeTabId],
			[LoginTabId],
			[UserTabId],
			[AdminTabId],
			[SplashTabId],
			[SearchTabId],
			[CreatedByUserID],
			[CreatedOnDate],
			[LastModifiedByUserID],
			[LastModifiedOnDate]
		)
		VALUES (
			@PortalID,
			@CultureCode,
			@PortalName,
			@LogoFile, 
			@FooterText,
			@Description,
			@KeyWords,
			@BackgroundFile,
			@HomeTabId ,
			@LoginTabId ,
			@UserTabId,
			@AdminTabid,
			@SplashTabId  ,
			@SearchTabId,
			-1,
			getdate(),
			-1,
			getdate()
		)
	END
GO
